﻿using System;
using System.Web.Http;
using eCommMongo.Core;
using eCommMongo.Core.Helper;
using eCommMongo.Service.Loggings;
using eCommMongo.Service.Products;
using yiCommerce.Core;
using yiCommerce.Service.Messages;

namespace eCommMongo.Web.Controllers.api
{
    public class InsertProductPictureRequest
    {
        public string PictureId { get; set; }
        public string ProductId { get; set; }
        public int DisplayOrder { get; set; }
    }

    public class InsertProductPictureResult
    {
        public string Status { get; set; }

        public string Message { get; set; }

        public string Id { get; set; }
    }
    public class ProductPictureApiController : ApiController
    {
        private IProductService  _productService;
        private IActivityService _activityService;
        private IWorkContext _workContext;
        private IMessageService _messageService;

        public ProductPictureApiController(IProductService productService, IActivityService activityService, IWorkContext workContext, IMessageService messageService)
        {
            _productService = productService;
            _activityService = activityService;
            _workContext = workContext;
            _messageService = messageService;
        }

        public InsertProductPictureResult InsertProductPicture(InsertProductPictureRequest request)
        {
            var result = new InsertProductPictureResult();


            try
            {

                var productPictureId = _productService.InsertProductPicture(request.ProductId, request.PictureId,request.DisplayOrder);

                result.Status = ConstInfo.ResultSuccessStatus;
                result.Id = productPictureId;

                _activityService.InsertActivity("InsertProductPicture", JsonHelper.ToJson(request), _workContext.CurrentCustomer);
                //SuccessNotification(_localizationService.GetResource("Admin.Catalog.Products.Added"));
                return result;
            }
            catch (Exception e)
            {
                result.Status = ConstInfo.ResultFailedStatus;
                result.Message = e.Message;
                return result;
            }

        }

        [HttpPost]
        public ProductPictureDeleteResult DeleteProductPicture(ProductPictureDeleteRequest request)
        {
            var result = new ProductPictureDeleteResult();


            try
            {

               _productService.DeleteProductPicture(request.ProductPictureId);

               result.Message = _messageService.GetResourceValue(Messages.ProductPictureDeletedSuccess, 0);
                result.Status = ConstInfo.ResultSuccessStatus;

                //_activityService.InsertActivity("InsertProductPicture", JsonHelper.ToJson(request), _workContext.CurrentCustomer);
                //SuccessNotification(_localizationService.GetResource("Admin.Catalog.Products.Added"));
                return result;
            }
            catch (Exception e)
            {
                result.Status = ConstInfo.ResultFailedStatus;
                result.Message = e.Message;
                return result;
            }
        }

    }

    public class ProductPictureDeleteRequest
    {
        public string ProductPictureId { get; set; }
    }

    public class ProductPictureDeleteResult
    {
        public string Status { get; set; }

        public string Message { get; set; }
    }
}
